package com.woniuxy.hrp.web.AdminController;

import com.woniuxy.hrp.entity.Doctor;
import com.woniuxy.hrp.entity.PageBean;
import com.woniuxy.hrp.service.DoctorService;
import com.woniuxy.hrp.unityhandler.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *@ClassName DoctorSetController
 *@Description
 *@Author TJ
 *@Date 2022/9/4 20:24
 *@Version 1.0
 **/
@RestController
@RequestMapping("/api/v1/doctorSet")
public class DoctorSetController {
    @Autowired
    private DoctorService doctorService;
    /**
     *@Description 管理员功能：查询所有的医生列表(带分页功能)
     *@Author TJ
     *@Version 1.0
     **/
    @GetMapping("/selectAll/{current}/{limit}")
    public ResponseEntity selectAll(@PathVariable(value="current")int current, @PathVariable (value="limit")int limit){
        PageBean<Doctor> pageBean = doctorService.getByPage(current,limit);
        return new ResponseEntity(ResponseEntity.SUCCESS.getCode(),ResponseEntity.SUCCESS.getMsg(),pageBean);
    }

    /**
     *@Description 管理员功能：增加医生
     *@Author TJ
     *@Version 1.0
     **/
    @PostMapping("add")
    public ResponseEntity add( @RequestBody Doctor doctor){
        doctorService.add(doctor);
        return new ResponseEntity<>(ResponseEntity.SUCCESS.getCode(),ResponseEntity.SUCCESS.getMsg(),null);
    }

    /**
     *@Description 管理员功能：根据id医生删除（逻辑）
     *@Author TJ
     *@Version 1.0
     **/
    @GetMapping("del/{id}")
    public ResponseEntity del(@PathVariable (value = "id")int id){
        doctorService.delete(id);
        return new ResponseEntity<>(ResponseEntity.SUCCESS.getCode(),ResponseEntity.SUCCESS.getMsg(),null);
    }

    /**
     *@Description 管理员功能：修改医生属性
     *@Author TJ
     *@Version 1.0
     **/
    @PostMapping("/update")
    public ResponseEntity update( @RequestBody Doctor doctor){
        doctorService.updateById(doctor);
        return new ResponseEntity<>(ResponseEntity.SUCCESS.getCode(),ResponseEntity.SUCCESS.getMsg(),null);
    }
}
 